package com.oa.controller;
import com.oa.api.LeaveServiceApi;
import com.oa.dto.Msg;
import com.oa.po.Leave;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RestController
public class LeaveController {
    @Autowired(required = false)
    LeaveServiceApi leaveServiceApi;
    Msg msg = new Msg();
    //对外添加请假申请的接口
    @CrossOrigin
    @PostMapping("/aa")
    public Msg add(@RequestBody Leave leave) {
        int i = leaveServiceApi.addLeave(leave);
        if (i == 1) {
            msg.setCode(200);
            msg.setMsg("申请成功");
        } else {
            msg.setCode(-100);
            msg.setMsg("申请失败");

        }
        return msg;

    }

    //对外查询请假申请的接口
    @CrossOrigin
    @PostMapping("/qq")
    public Msg find(@RequestBody Map map) {
        System.out.println(map.get("user_name"));
        List<Leave> leaves = leaveServiceApi.list_lever(map);

        if (leaves != null) {
            msg.setCode(200);
            msg.setMsg("查询成功");
            msg.setData(leaves);
        } else {
            msg.setCode(-100);
            msg.setMsg("查询失败");
        }
        return msg;
    }


}
